package com.cisetech.util;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils  extends org.apache.commons.lang3.StringUtils{

	public static boolean isEmpty(String string) {
		if (string == null || string.trim().equals("")) {
			return true;
		}
		return false;
	}
	public static String generateString(int len) {
		String source = "abcdefghijklmnopqrstuvwxyz1234567890";
		StringBuilder sb = new StringBuilder();
		Random random = new Random();
		for (int i = 0; i < len; i++) {
			sb.append(source.charAt(random.nextInt(source.length())));
		}
		return sb.toString();
	}

	public static String getUrl(String url) {
		if (isEmpty(url)) {
			return url;
		} else {
			String[] urls = url.split("\\?");
			return urls[0];
		}
	}
	public static String replaceBlank(String str) {
	        String dest = "";
	        if (str!=null) {
	            Pattern p = Pattern.compile("\n");
	            Matcher m = p.matcher(str);
	            dest = m.replaceAll("");
	        }
	        return dest;
	}
	public static String processStrings(String str)
	    {
	        if(str != null)
	        {
	            str = replace(str, "&", "&amp;");
	            str = replace(str, " ", "&nbsp;");
	            str = replace(str, "<", "&lt;");
	            str = replace(str, ">", "&gt;");
	            str = replace(str, "\r\n", "<br>");
	            str = replace(str, "\"", "&quot;");

	            return (str);
	        }
	        else
	            return (str);
	}
	
	
	
	
	
}
